using System;
using System.Collections.Generic;
using System.Text;
using AUSRIS.Reports.Utilities.Deployment.Logging;

namespace AUSRIS.Reports.Utilities.Deployment.Logging.ConsoleLogger
{
	public class Logger : ILogger
	{
		#region Private Fields

		private bool showTimestamp;

		#endregion

		#region Public Properties

		public bool ShowTimestamp
		{
			get
			{
				return showTimestamp;
			}
			set
			{
				showTimestamp = value;
			}
		}

		#endregion

		#region ILogger Members

		public virtual void LogMessage(string message)
		{
			if ( this.showTimestamp )
			{
				Console.WriteLine("{0}{1}{2}", DateTime.Now.TimeOfDay.ToString(), '\t', message);
			}
			else
			{
				Console.WriteLine(message);
			}
		}

		public virtual void LogMessage(string format, params object[] args)
		{
			this.LogMessage(string.Format(format, args));
		}

		public virtual void LogSuccess(string message)
		{
			Console.ForegroundColor = ConsoleColor.Green;
			this.LogMessage(message);
			Console.ResetColor();
		}

		public virtual void LogSuccess(string format, params object[] args)
		{
			Console.ForegroundColor = ConsoleColor.Green;
			this.LogMessage(format, args);
			Console.ResetColor();
		}

		public virtual void LogWarning(string message)
		{
			Console.ForegroundColor = ConsoleColor.Yellow;
			this.LogMessage(message);
			Console.ResetColor();
		}

		public virtual void LogWarning(string format, params object[] args)
		{
			Console.ForegroundColor = ConsoleColor.Yellow;
			this.LogMessage(format, args);
			Console.ResetColor();
		}

		public virtual void LogException(Exception ex)
		{
			Console.ForegroundColor = ConsoleColor.Red;
			Console.WriteLine();
			Console.Write("Exception:");
			Console.WriteLine(ex.ToString());
			Console.WriteLine();
			Console.ResetColor();
		}

		public virtual void LogNewLine()
		{
			Console.WriteLine();
		}

		public void LogHeader(string message)
		{
			Console.ForegroundColor = ConsoleColor.Cyan;
			this.LogNewLine();
			this.LogMessage(new string('-', 20));
			this.LogMessage(message);
			Console.ResetColor();
		}

		public void LogHeader(string format, params object[] args)
		{
			Console.ForegroundColor = ConsoleColor.Cyan;
			this.LogNewLine();
			this.LogMessage(new string('-', 20));
			this.LogMessage(format, args);
			Console.ResetColor();
		}

		public virtual void Flush()
		{
		}

		#endregion
	}
}
